home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PD Collection CD 1
/
PD Collection CD 1.iso
/
programer2
/
pari2
/
pari
/
other
/
plot_X
< prev
next >
Wrap
Text File
|
1991-11-28
|
8KB
|
244 lines
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* */
/* PLOT EN HAUTE RESOLUTION */
/* */
/* copyright Babe Cool */
/* */
/* */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
# include "genpari.h"
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#define IDEC 90
#define JDEC 5
void xerror()
{
err(talker, "Problem with the X Window system");
}
GEN ploth(ep,a,b,ch)
entree *ep;
GEN a,b;
char *ch;
{
long av = avma,av2,jz,j,i,sig,is,js,iz;
GEN p1,p2,p3,p4,ysml,ybig,x,diff,dyj,dx,y[2000];
char c1[20], c2[20], c3[20], c4[20];
XPoint points[2000];
Display *display;
Window win;
XSizeHints size_hints;
XEvent report;
GC gc;
XFontStruct *font_info;
int screen, width, height;
sig=gcmp(b,a); if(!sig) return gnil;
if(sig<0) {x=a;a=b;b=x;}
if (!(display = XOpenDisplay(NULL)))
err(talker, "no X server");
if (!(font_info = XLoadQueryFont(display, "9x15")))
err(talker, "cannot open 9x15 font");
XSetErrorHandler(xerror);
XSetIOErrorHandler(xerror);
screen = DefaultScreen(display);
width = DisplayWidth(display, screen) - 40;
height = DisplayHeight(display, screen) - 60;
is = width - IDEC - 5;
js = height - 25;
for(i=0;i<=is;i++) y[i]=cgetr(3);
newvalue(ep,cgetr(3)); x=ep->value;
gaffect(a,x);
dx=gdivgs(gsub(b,a),is); ysml = ybig = gzero;
av2=avma;
for(i=0;i<=is;i++)
{
gaffect(lisexpr(ch), y[i]);
if(gcmp(y[i], ysml) < 0) ysml = y[i]; else if(gcmp(y[i], ybig) > 0) ybig = y[i];
gaddz(x,dx,x);avma=av2;
}
diff = gsub(ybig, ysml);
if(gcmp0(diff)) {ybig=gaddsg(1,ybig);diff=gun;}
dyj = gdivsg(js, diff); av2 = avma;
for(i = 0; i <= is; i++)
{
points[i].x = IDEC + i;
points[i].y = JDEC + itos(ground(gmul(gsub(ybig, y[i]),dyj)));
avma=av2;
}
jz = JDEC + itos(ground(gmul(ybig,dyj)));
if(gsigne(a)*gsigne(b)<0) iz = IDEC + itos(ground(gmulsg(is, gdiv(a, gsub(a, b)))));
p1=cgetr(4); gaffect(ybig,p1); sprintf(c1,"%9.3lf",rtodbl(p1));
p2=cgetr(4); gaffect(ysml,p2); sprintf(c2,"%9.3lf",rtodbl(p2));
p3=cgetr(4); gaffect(a,p3); sprintf(c3,"%9.3lf",rtodbl(p3));
p4=cgetr(4); gaffect(b,p4); sprintf(c4,"%9.3lf",rtodbl(p4));
win = XCreateSimpleWindow(display, RootWindow(display, screen), 0, 0, width, height, 4,
BlackPixel(display, screen), WhitePixel(display, screen));
size_hints.flags = PPosition | PSize;
size_hints.x = 0;
size_hints.y = 0;
size_hints.width = width;
size_hints.height = height;
XSetStandardProperties(display, win, "ploth", NULL, NULL, NULL, 0, &size_hints);
XSelectInput(display, win, ExposureMask | ButtonPressMask);
gc = XCreateGC(display, win, 0, NULL);
XSetFont(display, gc, font_info->fid);
XSetForeground(display, gc, BlackPixel(display, screen));
XMapWindow(display, win);
for(;;)
{
XNextEvent(display, &report);
if (report.type != Expose) break;
while (XCheckTypedEvent(display, Expose, &report));
XDrawRectangle(display, win, gc, IDEC, JDEC, is, js);
XDrawLine(display, win, gc, IDEC, jz, IDEC + is, jz);
if (iz) XDrawLine(display, win, gc, iz, JDEC, iz, js + JDEC);
XDrawString(display, win, gc, 0, 15, c1, strlen(c1));
XDrawString(display, win, gc, 0, height - 30, c2, strlen(c2));
XDrawString(display, win, gc, IDEC - 20, height - 5, c3, strlen(c3));
XDrawString(display, win, gc, width - 90, height - 5, c4, strlen(c4));
XDrawLines(display, win, gc, points, is+1, 0);
}
XUnloadFont(display, font_info->fid);
XFreeGC(display, gc);
XCloseDisplay(display);
avma = av;
killvalue(ep);
return gnil;
}
#define NBPOINTS 1500
GEN ploth2(ep,a,b,ch)
entree *ep;
GEN a,b;
char *ch;
{
long av = avma,av2,jz,j,i,sig,is,js,iz;
GEN p1,p2,p3,p4,xsml,xbig,ysml,ybig,t,diffx,diffy,dy,dx,dt,x[NBPOINTS],y[NBPOINTS];
char c1[20], c2[20], c3[20], c4[20];
XPoint points[NBPOINTS];
Display *display;
Window win;
XSizeHints size_hints;
XEvent report;
GC gc;
XFontStruct *font_info;
int screen, width, height;
sig=gcmp(b,a); if(!sig) return gnil;
if(sig<0) {t=a;a=b;b=t;}
if (!(display = XOpenDisplay(NULL)))
err(talker, "no X server");
if (!(font_info = XLoadQueryFont(display, "9x15")))
err(talker, "cannot open 9x15 font");
XSetErrorHandler(xerror);
XSetIOErrorHandler(xerror);
screen = DefaultScreen(display);
width = DisplayWidth(display, screen) - 40;
height = DisplayHeight(display, screen) - 60;
is = width - IDEC - 5;
js = height - 25;
for(i=0;i<NBPOINTS;i++) {x[i] = cgetr(3); y[i]=cgetr(3);}
newvalue(ep,cgetr(3)); t=ep->value;
gaffect(a,t);
dt=gdivgs(gsub(b,a),NBPOINTS); xsml = xbig = ysml = ybig = gzero;
av2=avma;
for(i=0;i<NBPOINTS;i++)
{
p1 = lisexpr(ch);
gaffect(p1[1], x[i]); gaffect(p1[2], y[i]);
if(gcmp(x[i], xsml) < 0) xsml = x[i]; else if(gcmp(x[i], xbig) > 0) xbig = x[i];
if(gcmp(y[i], ysml) < 0) ysml = y[i]; else if(gcmp(y[i], ybig) > 0) ybig = y[i];
gaddz(t,dt,t);
avma=av2;
}
diffx = gsub(xbig, xsml);
if(gcmp0(diffx)) {xbig=gaddsg(1,xbig);diffx=gun;}
diffy = gsub(ybig, ysml);
if(gcmp0(diffy)) {ybig=gaddsg(1,ybig);diffy=gun;}
dy = gdivsg(js, diffy);
dx = gdivsg(is, diffx);
av2 = avma;
for(i = 0; i < NBPOINTS; i++)
{
points[i].x = IDEC + itos(ground(gmul(gsub(x[i],xsml),dx)));
points[i].y = JDEC + itos(ground(gmul(gsub(ybig, y[i]),dy)));
avma=av2;
}
iz = IDEC - itos(ground(gmul(xsml, dx)));
jz = JDEC + itos(ground(gmul(ybig, dy)));
p1=cgetr(4); gaffect(ybig,p1); sprintf(c1,"%9.3lf",rtodbl(p1));
p2=cgetr(4); gaffect(ysml,p2); sprintf(c2,"%9.3lf",rtodbl(p2));
p3=cgetr(4); gaffect(xsml,p3); sprintf(c3,"%9.3lf",rtodbl(p3));
p4=cgetr(4); gaffect(xbig,p4); sprintf(c4,"%9.3lf",rtodbl(p4));
win = XCreateSimpleWindow(display, RootWindow(display, screen), 0, 0, width, height, 4,
BlackPixel(display, screen), WhitePixel(display, screen));
size_hints.flags = PPosition | PSize;
size_hints.x = 0;
size_hints.y = 0;
size_hints.width = width;
size_hints.height = height;
XSetStandardProperties(display, win, "ploth", NULL, NULL, NULL, 0, &size_hints);
XSelectInput(display, win, ExposureMask | ButtonPressMask);
gc = XCreateGC(display, win, 0, NULL);
XSetFont(display, gc, font_info->fid);
XSetForeground(display, gc, BlackPixel(display, screen));
XMapWindow(display, win);
for(;;)
{
XNextEvent(display, &report);
if (report.type != Expose) break;
while (XCheckTypedEvent(display, Expose, &report));
XDrawRectangle(display, win, gc, IDEC, JDEC, width - IDEC - 5, js);
XDrawLine(display, win, gc, iz, JDEC, iz, js + JDEC);
XDrawLine(display, win, gc, IDEC, jz, width - 5, jz);
XDrawString(display, win, gc, 0, 15, c1, strlen(c1));
XDrawString(display, win, gc, 0, height - 30, c2, strlen(c2));
XDrawString(display, win, gc, IDEC - 20, height - 5, c3, strlen(c3));
XDrawString(display, win, gc, width - 90, height - 5, c4, strlen(c4));
XDrawLines(display, win, gc, points, NBPOINTS, 0);
}
XUnloadFont(display, font_info->fid);
XFreeGC(display, gc);
XCloseDisplay(display);
avma = av;
killvalue(ep);
return gnil;
}